<?php

namespace Biz\model;

use Doraemon\pockets\datebase\BaseDbModel;
use Doraemon\tools\HhzClient;

class GoodsStockLog extends BaseDbModel
{


    const _CONFIG_FILE_ = 'db_shop';

    const _CONFIG_SELECT_ = 'db_shop';

    const _DATABASE_ = 'shop';

    const _TABLE_NAME = 'goods_stock_log';


    const TYPE_NORMAL_GOODS = 1; //普通状态下商品

    const TYPE_LIMIT_TIME_ROBBING = 2; // 限时抢状态下商品

    const TYPE_ADMIN_ACTION = 3; // 后台用户操作

    const TYPE_LIMIT_PINTUAN = 4; // 拼团状态下商品


    const TYPE_DESC_MAP = [
        self::TYPE_NORMAL_GOODS => '普通商品类型',

        self::TYPE_LIMIT_TIME_ROBBING => '限时抢商品类型',

        self::TYPE_ADMIN_ACTION => '后台管理员操作类型',

        self::TYPE_LIMIT_PINTUAN => '拼团商品类型'
    ];


    public static function addLog($foreign_id, $p_order_no, $goods_id, $type, $promo_id, $promo_type,$sku_id, $change_data, $action_uid,$target_data)
    {
        self::insert([
            'foreign_id' => $foreign_id,
            'p_order_no' => $p_order_no,
            'goods_id' => $goods_id,
            'type' => $type,
            'promo_id' => $promo_id,
			'promo_type' => $promo_type,
            'sku_id' => $sku_id,
            'change_num' => $change_data,
            'target_num' => $target_data,
            'action_uid' => $action_uid,
            'add_time' => date("Y-m-d H:i:s"),
        ]);

        return self::id();
    }


    public static function getByForeignId($foreign_ids, $type = 0)
    {
        $where['foreign_id'] = $foreign_ids;
        if ($type) {
            $where['type'] = $type;
        }
        return self::select("*", $where);
    }


}